﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BaseData;
using BaseData.Exts;
using BaseData.Models;
using BaseLib.Helper;
using BaseUtility;

namespace WebUI.Ashx.Acc.Staff
{
    /// <summary>
    /// NewsAdminGroupView 的摘要说明
    /// </summary>
    public class NewsAdminGroupNodeView : Base, IHttpHandler
    {
        private static readonly AccClass _accId = new AccExts(new GetAccType().Parse(Request.QueryString["url"])).Instances;
        public void ProcessRequest(HttpContext context)
        {
            if (_accId.Id == 0 || string.IsNullOrWhiteSpace(_accId.Name) || _accId.Type == 0) return;
            using (var ctx = new ContextExt())
            {
                var list = new Web_Base_News_Node() { FlagStatus = 0, FlagView = 0, }; // 防止结果集为空时返回空数据，导致添加数据时出现JS脚本错误。
                var action = (Enums.Action)Enum.Parse(typeof(Enums.Action), context.Request.QueryString["action"], true);
                if (action == Enums.Action.ActEdit)
                {
                    var id = context.Request.QueryString["id"].ToInt(0);
                    var sql = (from q in ctx.Web_Base_News_Node where q.PkId == id select q);
                    if (sql.Any()) list = sql.FirstOrDefault();
                }
                context.Response.Write(list.ObjectsToJson());
                context.Response.ContentType = "text/plain";
            }
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}